<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLogisticsPlan extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $sql = "CREATE TABLE `logistics_plan` (
            `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
            `type` tinyint(2) NOT NULL DEFAULT '0' COMMENT '类型',
            `product_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '产品ID',
            `sku` varchar(30) NOT NULL DEFAULT '',
            `qty` int(11) NOT NULL DEFAULT '0' COMMENT '总数',
            `qty_ctn` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '装箱率',
            `shipable_qty` int(11) NOT NULL DEFAULT '0' COMMENT '可发数量',
            `expected_qty` int(11) NOT NULL DEFAULT '0' COMMENT '预计可发数量',
            `expected_date` date DEFAULT NULL COMMENT '预计到货日期',
            `planned_qty` int(11) NOT NULL DEFAULT '0' COMMENT '计划中的数量',
            `shipped_qty` int(11) NOT NULL DEFAULT '0' COMMENT '已发数量',
            `purchase_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '采购明细ID',
            `label` char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '外箱标签',
            `order_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '货代单',
            `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '目标仓库',
            `transport_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '物流方式',
            `customs_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '报关类型',
            `ctn_weight` decimal(6,2) NOT NULL DEFAULT '0.00',
            `ctn_g_weight` decimal(6,2) NOT NULL DEFAULT '0.00',
            `ctn_length` decimal(6,2) NOT NULL DEFAULT '0.00',
            `ctn_width` decimal(6,2) NOT NULL DEFAULT '0.00',
            `ctn_height` decimal(6,2) NOT NULL DEFAULT '0.00',
            `remark` text,
            UNIQUE KEY `id` (`id`,`order_id`),
            KEY `type` (`type`),
            KEY `product_id` (`product_id`),
            KEY `purchase_id` (`purchase_id`),
            KEY `order_id` (`order_id`),
            KEY `warehouse_id` (`warehouse_id`),
            KEY `transport_type` (`transport_type`),
            KEY `label` (`label`),
            KEY `qty` (`qty`),
            KEY `planned_qty` (`planned_qty`),
            KEY `shipped_qty` (`shipped_qty`)
          ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";

          \DB::statement($sql);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('logistics_plan');
    }
}
